/************************************
 * created by Tonk (tonk@ctonk.com) *
 ************************************/

// logs.cpp

#ifndef LOGS_CPP
#define LOGS_CPP

#include "definitions.h"
#include "logs.h"

bool log( int type, const char* text ) {
	std::ofstream log;
	switch( type ) {
		case SERVER: log.open( SERVER_LOG, std::ofstream::app ); break;
		case WORLD: log.open( WORLD_LOG, std::ofstream::app ); break;
		case EVENT: log.open( EVENT_LOG, std::ofstream::app ); break;
		case ACTION: log.open( ACTION_LOG, std::ofstream::app ); break;
		case ACCOUNT: log.open( ACCOUNT_LOG, std::ofstream::app ); break;
		case OMNINET: log.open( OMNINET_LOG, std::ofstream::app ); break;
		default: log.open( DEFAULT_LOG, std::ofstream::app ); break;
	}
	log << Timestamp::Instance().GetDateTime() << "\n\t" << text << "\n\n";
	log.close();
	return true;
}

bool log( int type, char* text ) {
	std::ofstream log;
	switch( type ) {
		case SERVER: log.open( SERVER_LOG, std::ofstream::app ); break;
		case WORLD: log.open( WORLD_LOG, std::ofstream::app ); break;
		case EVENT: log.open( EVENT_LOG, std::ofstream::app ); break;
		case ACTION: log.open( ACTION_LOG, std::ofstream::app ); break;
		case ACCOUNT: log.open( ACCOUNT_LOG, std::ofstream::app ); break;
		case OMNINET: log.open( OMNINET_LOG, std::ofstream::app ); break;
		default: log.open( DEFAULT_LOG, std::ofstream::app ); break;
	}
	log << Timestamp::Instance().GetDateTime() << "\n\t" << text << "\n\n";
	log.close();
	return true;
}

bool log( int type, std::string& text ) {
	std::ofstream log;
	switch( type ) {
		case SERVER: log.open( SERVER_LOG, std::ofstream::app ); break;
		case WORLD: log.open( WORLD_LOG, std::ofstream::app ); break;
		case EVENT: log.open( EVENT_LOG, std::ofstream::app ); break;
		case ACTION: log.open( ACTION_LOG, std::ofstream::app ); break;
		case ACCOUNT: log.open( ACCOUNT_LOG, std::ofstream::app ); break;
		case OMNINET: log.open( OMNINET_LOG, std::ofstream::app ); break;
		default: log.open( DEFAULT_LOG, std::ofstream::app ); break;
	}
	log << Timestamp::Instance().GetDateTime() << "\n\t" << text << "\n\n";
	log.close();
	return true;
}

bool log( std::string& name, int level, char* text ) {
	std::string file;
	std::ofstream log;

	file = ( level > 110 ) ? ADMIN_LOG_DIR : PLAYER_LOG_DIR;
	file << name << ".log";

	log.open( file.c_str(), std::ofstream::app );
	log << Timestamp::Instance().GetDateTime() << "\n\t" << text << "\n\n";
	log.close();

	return true;
}

bool log( std::string& name, int level, const char* text ) {
	std::string file;
	std::ofstream log;

	file = ( level > 110 ) ? ADMIN_LOG_DIR : PLAYER_LOG_DIR;
	file << name << ".log";

	log.open( file.c_str(), std::ofstream::app );
	log << Timestamp::Instance().GetDateTime() << "\n\t" << text << "\n\n";
	log.close();

	return true;
}

bool log( std::string& name, int level, std::string& text ) {
	std::string file;
	std::ofstream log;

	file = ( level > 110 ) ? ADMIN_LOG_DIR : PLAYER_LOG_DIR;
	file << name << ".log";

	log.open( file.c_str(), std::ofstream::app );
	log << Timestamp::Instance().GetDateTime() << "\n\t" << text << "\n\n";
	log.close();

	return true;
}

#endif // #ifndef LOGS_CPP
